package 华为机试8月16日机试;

import java.util.Scanner;

public class 华为机试8月16日第1题 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String[] a = sc.nextLine().trim().split("\\s+");
            System.out.println(count(a[0], a[1]));
        }
        sc.close();
    }

    private static int count(String str1, String str2) {
        if (str1.length() != str2.length())
            return -1;
        int num = 0;
        int max = 0;
        for (int i = 0; i < str1.length(); i++) {
            if (!Character.isDigit(str1.charAt(i)) || !Character.isDigit(str2.charAt(i)))
                return -1;
            if (str1.charAt(i) == str2.charAt(i)) {
                num++;
            } else {
                max = Math.max(num, max);
                num = 0;
            }
        }
        return max == 1 ? 0 : max;
    }
}
